﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MusteriTakipProgrami
{
    public partial class UrunAra : Form
    {
        private Form MusteriTakip;
        UrunEkle urunekle;
        UrunGuncelle urunguncelle;

        public UrunAra()
        {
            InitializeComponent();
        }

        private void UrunAra_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'mUSTERITAKIPDataSet1.URUN' table. You can move, or remove it, as needed.
            this.uRUNTableAdapter.Fill(this.mUSTERITAKIPDataSet1.URUN);

        }

        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.uRUNTableAdapter.Ara(this.mUSTERITAKIPDataSet1.URUN, uRUN_ADIToolStripTextBox.Text, uRUN_KODUToolStripTextBox.Text);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void UrunEkle_Btn_Click(object sender, EventArgs e)
        {
            if (urunekle != null)
                urunekle.Dispose();
            urunekle = new UrunEkle();
            urunekle.MdiParent = MusteriTakip;

            urunekle.Show();
        }
        public static string urunad;
        public static int urunid;
        public static string volumep;
        public static int satisfiyat;
        public static string urunkod;
        private void UrunGuncelle_Btn_Click(object sender, EventArgs e)
        {
            urunid = Convert.ToInt32(this.urunaradgv.SelectedRows[0].Cells[0].Value.ToString());
            urunad = this.urunaradgv.SelectedRows[0].Cells[1].Value.ToString();
            volumep = this.urunaradgv.SelectedRows[0].Cells[2].Value.ToString();
            satisfiyat = Convert.ToInt32(this.urunaradgv.SelectedRows[0].Cells[3].Value.ToString());
            urunkod = this.urunaradgv.SelectedRows[0].Cells[4].Value.ToString();

            if (urunguncelle != null)
                urunguncelle.Dispose();
            urunguncelle = new UrunGuncelle();
            urunguncelle.MdiParent = MusteriTakip;

            urunguncelle.Show();
        }

        private void Cikis_Btn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void UrunSil_Btn_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Silmek istediğinize emin misiniz?", "Uyarı", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                urunid = Int32.Parse(this.urunaradgv.SelectedRows[0].Cells[0].Value.ToString());

                if (this.urunaradgv.SelectedRows.Count > 0 && this.urunaradgv.SelectedRows[0].Index != this.urunaradgv.Rows.Count - 1)
                {
                    // SqlConnection baglanti = new SqlConnection("Data Source=.;Initial Catalog=MUSTERITAKIP;Integrated Security=True");




                    SqlConnection baglanti = new SqlConnection("Data Source=.;Initial Catalog=MUSTERITAKIP;Integrated Security=True");

                    this.urunaradgv.Rows.RemoveAt(this.urunaradgv.SelectedRows[0].Index);

                    string sorgu = "delete from URUN where ID=@ID";
                    // Label kodlbl = (Label)this.dataGridView8.Rows.RemoveAt(this.dataGridView8.SelectedRows[0].Index);
                    // Response.Write(kodlbl.Text);
                    //SqlConnection baglanti = new SqlConnection(baglanti);
                    SqlCommand komut = new SqlCommand(sorgu, baglanti);
                    komut.Parameters.AddWithValue("@ID", urunid);
                    baglanti.Open();
                    komut.ExecuteNonQuery();
                    baglanti.Close();


                }
            }
        }
    }
}
